package com.ms.controller;

import com.ms.common.Result;
import com.ms.pojo.AttendanceRecord;
import com.ms.service.AttendanceRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/attendance")
@Tag(name = "员工考勤打卡接口")
public class AttendanceRecordController {

    @Autowired
    private AttendanceRecordService attendanceRecordService;

    /**
     * 员工签到
     */
    @PostMapping("/checkIn")
    @Operation(summary = "员工签到")
    public Result<AttendanceRecord> checkIn(@RequestParam Integer empId) {
        AttendanceRecord record = attendanceRecordService.checkIn(empId);
        if (record != null) {
            return Result.success(record);
        }
        return Result.error("签到失败（已签到或参数错误）");
    }

    /**
     * 员工签退
     */
    @PostMapping("/checkOut")
    @Operation(summary = "员工签退")
    public Result<AttendanceRecord> checkOut(@RequestParam Integer empId) {
        AttendanceRecord record = attendanceRecordService.checkOut(empId);
        if (record != null) {
            return Result.success(record);
        }
        return Result.error("签退失败（未签到或已签退）");
    }

    /**
     * 查询当天考勤状态
     */
    @GetMapping("/today/{empId}")
    @Operation(summary = "查询员工当天考勤状态")
    public Result<AttendanceRecord> getTodayStatus(@PathVariable Integer empId) {
        return Result.success(attendanceRecordService.getTodayAttendance(empId));
    }
    /**
     * 查询员工考勤记录
     */
    @PostMapping("/records")
    @Operation(summary = "查询员工考勤记录")
    public Result<List<AttendanceRecord>> getRecords() {
        return Result.success(attendanceRecordService.getAllRecords());
    }
}